package cn.lightpm.entity.task;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import cn.lightpm.entity.AbstractEntity;
import cn.lightpm.entity.account.User;

import com.google.common.collect.Lists;

@Entity
@Table(name = "TASK")
public class Task extends AbstractEntity {

	private static final long serialVersionUID = 4558557344111161990L;

	private String name;

	private String description;

	private TaskType type;

	private TaskStatus status;

	private Date startDate;

	private Date deadline;

	private Date finishDate;

	private List<User> assigneeList = Lists.newArrayList();

	@Column(nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "TYPE")
	public TaskType getType() {
		return type;
	}

	public void setType(TaskType type) {
		this.type = type;
	}

	public TaskStatus getStatus() {
		return status;
	}

	public void setStatus(TaskStatus status) {
		this.status = status;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getDeadline() {
		return deadline;
	}

	public void setDeadline(Date deadline) {
		this.deadline = deadline;
	}

	public Date getFinishDate() {
		return finishDate;
	}

	public void setFinishDate(Date finishDate) {
		this.finishDate = finishDate;
	}

	@ManyToMany
	@JoinTable(name = "TASK_MEMBER", joinColumns = { @JoinColumn(name = "TASK_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID") })
	@Fetch(FetchMode.SUBSELECT)
	@OrderBy("id")
	public List<User> getAssigneeList() {
		return assigneeList;
	}

	public void setAssigneeList(List<User> assigneeList) {
		this.assigneeList = assigneeList;
	}

}
